<%@ page pageEncoding="utf-8"%>
<%@page import="org.myhibernate.util.Json"%>
<%@page import="org.myhibernate.Template"%>
<%@page import="org.myhibernate.ProxyTemplate"%>
<%@page import="org.myhibernate.core.method.PageSizeQuery"%>
<%@page import="java.util.List"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="org.personal.entity.Page"%>
<%@page import="org.personal.entity.Layout"%>
<%@page import="org.personal.entity.User"%>
<%@page import="org.personal.Constants"%>
<%@page import="org.personal.entity.UserPage"%>
<%@page import="org.personal.util.UserUtil"%>
<%@page import="org.personal.entity.Portlet"%>
<%
User user=(User)request.getSession().getAttribute(Constants.USER);
Json json=new Json();
if(user!=null)
{
	String layoutId=request.getParameter("id");
	if((layoutId==null)||("".equals(layoutId)))
	{
		layoutId="-1";
	}
	Template template=new ProxyTemplate(Layout.class).getInstance();
	try
	{
		Layout layout=(Layout)template.get(Integer.parseInt(layoutId));
		boolean isCreate=false;
		if(layout ==null)
		{
			layout=new Layout();
			isCreate=true;
		}
		//
		String title=request.getParameter("title");
		String pagePath=request.getParameter("pagePath");
		String defaultLayout=request.getParameter("defaultLayout");
		title=URLDecoder.decode(title,"utf-8");
		layout.setTitle(title);
		layout.setPagePath(pagePath);
		layout.setDefaultLayout(Boolean.parseBoolean(defaultLayout));
		
		if(isCreate)
		{
			template.save(layout);
		}else
		{
			template.update(layout);
		}
		json.add("result","ok");
	}catch(Exception exception)
	{
		json.add("result","no");
		json.add("message",exception.toString().trim());
	}
	finally
	{
		template.close();
	}
}else
{
	json.add("result","no");
	json.add("message","用户未登录");
}
out.println(json);
%>
